using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace star_questionnair.Models
{
    [Table("response")]
    public class Response
    {
        /*
         * id主键
         */
        [Column("id")]
        public int Id { get; set; }
        
        /*
         * 所属问卷ID
         */
        [Column("questionnaire_id")]
        public int QuestionnaireId { get; set; }

        [NotMapped]
        [JsonIgnore]
        public Questionnaire Questionnaire { get; set; } // 导航属性
        /*
         * 提交回答的用户ID
         */
        [Column("user_id")]
        public int UserId { get; set; }

        /*
         * 开始时间
         */
        [Column("start_time")]
        public DateTime StartTime { get; set; }

        /*
         * 提交时间
         */
        [Column("submitted_time")]
        public DateTime? SubmittedTime { get; set; }

        /*
         * 更新时间
         */
        [Column("updated_time")]
        public DateTime UpdatedTime { get; set; }

        [NotMapped]
        public ICollection<Answer> Answers { get; set; } // 导航属性

        public Response() 
        {
            Answers = new List<Answer>();
        }

        public Response(int id, int questionnaireId, int userId, DateTime startTime, DateTime submittedTime, DateTime updatedTime)
        {
            Id = id;
            QuestionnaireId = questionnaireId;
            UserId = userId;
            StartTime = startTime;
            SubmittedTime = submittedTime;
            UpdatedTime = updatedTime;
            Answers = new List<Answer>();
        }
    }
}